dojo.provide("miaigo.model.sgf.properties.Point");

dojo.require("miaigo.model.sgf.SGFProperty");

/* Properties to handle:
 *   B, W
 */

dojo.declare(
    "miaigo.model.sgf.properties.Point",
    [miaigo.model.sgf.SGFProperty],
    {
	onApply: function(game)
	{
	    var value = this.getValue();
	    if (!value)
	    {
		return;
	    }

	    switch (this.getID())
	    {
	    case "B":
		game.makeMove( {stone: "black", x: value.x, y: value.y} );
		break;
	    case "W":
		game.makeMove( {stone: "white", x: value.x, y: value.y} );
		break;
	    }
	},

	getValue: function(/*integer (optional)*/index)
	{
	    var value = this.getRawValue(index);

	    if (value.length != 2)
	    {
		return null;
	    }

	    if (value.charAt(0) >= 'a' &&
		value.charAt(0) <= 's' &&
		value.charAt(1) >= 'a' &&
		value.charAt(1) <= 's')
	    {
		return {
		    x: value.charCodeAt(0) - "a".charCodeAt(0),
		    y: value.charCodeAt(1) - "a".charCodeAt(0)
		};
	    }

	    return null;
	}
    });